package 代码随想2._3哈希表;

/**
 * @author XXX
 * @date 2024-01-14 21:43
 */

import java.util.HashMap;
import java.util.Map;

/**
 * https://leetcode.cn/problems/4sum-ii/description/
 */
public class _5四数相加Ⅱ {
    public int fourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) {
        int res = 0;
        int tmp;
        Map<Integer, Integer> map = new HashMap<>();
        for(int num1 : nums1){
            for(int num2 : nums2){
                tmp = num1 + num2;
                if(map.containsKey(tmp))
                    map.put(tmp,map.get(tmp) + 1);
                else
                    map.put(tmp,1);
            }
        }
        for (int num3 : nums3){
            for (int num4 : nums4){
                tmp = num3 + num4;
                if(map.containsKey(0-tmp))
                    res += map.get(0-tmp);
            }
        }
        return res;
    }
}
